import { Product } from "../../public/Product"

//具体产品类 1
class ConcreateProduct1 extends Product {
    constructor() {
        super()
    }

}
//具体产品类 2
class ConcreateProduct2 extends Product {
    constructor() {
        super()
    }
}

let ProductStorage: any = {
    ConcreateProduct1,
    ConcreateProduct2,
}


//简单工厂
class SimpleFactory {
    public static createProduct(className: string): Product {
        let product: Product
        //如果类名存在则根据类名创建具体实例
        if (ProductStorage[className]) {
            product = new (ProductStorage[className])()
        } else {
            throw new Error(`class ${className} does not exist`)
        }

        return product
    }
}

let SimpleFactoryTest = (className: string): void => {
    let myProduct: Product = SimpleFactory.createProduct(className)
    myProduct.price = 20
    console.log(myProduct);
}


SimpleFactoryTest('ConcreateProduct1')